<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>搜索详情-未借阅</title>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="renderer" content="webkit">
	<link rel="stylesheet" type="text/css" href="/css/base.css">
	<link rel="stylesheet" type="text/css" href="/css/searchinfoon.css">
</head>
<body>
<form>
<div class="searchInfo">
	<div class="homeTitle">
		<a href="/index/index/index"><div class="homeTitleMind">前锋图书馆</div></a>
		<div class="userHomeName"><a href="/index/screendetails/screendetails">查阅更多》</a></div>
	</div>
	<form>
	<div class="searchInfoMind">
		<div class="searchInfoOut">
		<input type="hidden" id="bid" value="{$status.id}">
			<div class="searchInfoImg"><img src="{$data.img}"></div>
			<div class="sbookName">{$data.bname}</div>
			{if condition="$status.states==0"}
			<div class="appointment">申请借阅</div>
			{else/}
			<div class="appointments">已申请</div>
			{/if}
		</div>
	</div>
	</form>
</div>
</body>
<script src="/js/jquery-3.1.1.min.js"></script>
<script src="/js/layer/layer.js"></script>
<script>
	//申请
	$('.searchInfoOut').on('click','.appointment',function(){
		var booksid = $("#bid").val();
		$.ajax({
	        type: "POST",
	        url: "/index/searchinfo/doapply",
	        data: {'bookid': booksid},
	        dataType: "json",
	        timeout: 3000,
	        success: function (data) {
	            console.log(data)
	            if(data==1){
	                layer.msg('预约成功！', {
	                    icon: 1,
	                    time: 1000
	                }, function () {
	                	var bhtml = '<div class="appointments">已申请</div>';
	                    $(".appointment").replaceWith(bhtml);
	                });
	            }else{
	                layer.msg('预约失败！', {
	                    icon: 2,
	                    time: 1000
	                });  
	            }
	        }
	    });
	})
	//取消申请
	$('.searchInfoOut').on('click','.appointments',function(){
		var booksid = $("#bid").val();
		$.ajax({
	        type: "POST",
	        url: "/index/searchinfo/cancelapply",
	        data: {'bookid': booksid},
	        dataType: "json",
	        timeout: 3000,
	        success: function (data) {
	            console.log(data)
	            if(data==1){
	                layer.msg('预约成功！', {
	                    icon: 1,
	                    time: 1000
	                }, function () {
	                	var bhtml = '<div class="appointment">取消申请</div>';
	                    $(".appointments").replaceWith(bhtml);
	                });
	            }else{
	                layer.msg('预约失败！', {
	                    icon: 2,
	                    time: 1000
	                });  
	            }
	        }
	    });
	})
</script>
</html>